package com.qtjf.qtmoneyservice.activity;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.qtjf.qtmoneyservice.R;
import com.qtjf.qtmoneyservice.constantSet.Constant;
import com.qtjf.qtmoneyservice.utils.RequestNetApi;
import com.qtjf.qtmoneyservice.widget.AddressDialog;
import com.qtjf.qtmoneyservice.widget.BankDialog;

import java.util.HashMap;

import impl.IHttpListener;

public class KaRenZhengActivity extends BaseActivity {

    ImageView mBack;
    TextView bankText;
    TextView cityText;
    EditText kaText;
    EditText phoneText;
    TextView submitBt;

    Handler handler=new Handler(){
        @Override
        public void dispatchMessage(Message msg) {
            super.dispatchMessage(msg);
            if(msg.arg1==6)
            {
                bankText.setText(msg.obj.toString());
            }
            else if(msg.arg1==3)
            {
                cityText.setText(msg.obj.toString());
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ka_ren_zheng);
        super.setTranslucent();

        initView();
        initData();
        initEvent();
    }

    private void initView() {
        mBack= (ImageView) findViewById(R.id.back_bt);
        bankText= (TextView) findViewById(R.id.bank_text);
        cityText= (TextView) findViewById(R.id.city_text);
        kaText= (EditText) findViewById(R.id.ka_text);
        phoneText= (EditText) findViewById(R.id.phone_text);
        submitBt= (TextView) findViewById(R.id.submit_bt);
    }

    private void initData() {
    }

    private void initEvent() {
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                KaRenZhengActivity.this.finish();
            }
        });

        bankText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BankDialog dialog=new BankDialog(KaRenZhengActivity.this,R.style.myTransparent,handler);
                dialog.show();
            }
        });


        cityText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AddressDialog dialog=new AddressDialog(KaRenZhengActivity.this,R.style.myTransparent,handler);
                dialog.show();
            }
        });


        submitBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                RequestNetApi requestNetApi=new RequestNetApi();
                requestNetApi.attach(new IHttpListener() {
                    @Override
                    public void success(String msg) {
                        Log.d("999",msg);
                    }

                    @Override
                    public void fail() {

                        Toast.makeText(KaRenZhengActivity.this,"网络请求失败",Toast.LENGTH_SHORT).show();
                    }
                });

                //http://118.89.185.176:8082/tanzhi/sumbitBank

                HashMap<String,String> map=new HashMap<String, String>();
                map.put("bankCardNo",kaText.getText().toString().trim());
                map.put("bankName",bankText.getText().toString().trim());
                map.put("region",cityText.getText().toString().trim());
                map.put("mobile",phoneText.getText().toString().trim());
                map.put("userMobile", Constant.getUsermobile());

                requestNetApi.postHttp(Constant.getHOMEADDRESS()+"tanzhi/sumbitBank",map);
            }
        });
    }
}
